﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace JaxDug.Core.HtmlHelpers
{
    public static class Helpers
    {
        public static MvcHtmlString ActionImageLink(this HtmlHelper htmlHelper, string imgSrc, string alt, string actionName, string controllerName, object routeValues, object lnkHtmlAttributes, object imgHtmlAttributes)
        {
            UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url;
            TagBuilder imgTag = new TagBuilder("img");
            imgTag.MergeAttribute("src", imgSrc);
            imgTag.MergeAttributes(new RouteValueDictionary(imgHtmlAttributes), true);
            string url = urlHelper.Action(actionName, controllerName, routeValues);

            TagBuilder imglink = new TagBuilder("a");
            imglink.MergeAttribute("href", url);
            imglink.InnerHtml = imgTag.ToString();
            imglink.MergeAttributes(new RouteValueDictionary(lnkHtmlAttributes), true);

            return new MvcHtmlString(imglink.ToString());
        }

        public static MvcHtmlString ImageLink(this HtmlHelper htmlHelper, string imgSrc, string alt, string linkUrl, object lnkHtmlAttributes, object imgHtmlAttributes)
        {
            TagBuilder imgTag = new TagBuilder("img");
            imgTag.MergeAttribute("src", imgSrc);
            imgTag.MergeAttribute("alt", alt);
            imgTag.MergeAttributes(new RouteValueDictionary(imgHtmlAttributes), true);
            string img = imgTag.ToString();

            TagBuilder imglink = new TagBuilder("a");
            imglink.MergeAttribute("href", linkUrl);
            imglink.InnerHtml = img;
            imglink.MergeAttributes(new RouteValueDictionary(lnkHtmlAttributes), true);

            return new MvcHtmlString(imglink.ToString());
        }
    }
}